<?php
declare (strict_types = 1);

namespace app\common\command;

use app\service\hash\Hash;
use services\adminUser\AdminUserManger;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use Throwable;

class UpdatePassword extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('update-password')
            ->addArgument('password', Argument::REQUIRED, "密码")
            ->addOption('user_id', null, Option::VALUE_OPTIONAL,'后台管理用户ID 默认为1',1)
            ->setDescription('修改后台管理员密码');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        try{
            $password = $input->getArgument('password');
            $pass = app(AdminUserManger::class)->createPassword($password);

            $id = $input->getOption('user_id');
            app(AdminUserManger::class)->update($id,[
                'password'=>$password
            ]);
        }catch(Throwable $e){
            echo $e;
        }
    }
}
